<template>
	<view class="page-bottom-fixed">
		<form @submit="form_submit" class="form-container">
			<view class="padding-main oh">
				<!-- 根据款号查询产品 -->
				<view class="form-gorup-tj oh">
					<view class="padding-top-pd">
						<input type="text" name="barCode" v-model="product_data.barCode" maxlength="15"
								placeholder-class="cr-grey" class="cr-base" placeholder="根据款号查询产品" @blur="demand_envent" />
					</view>
				</view>
				<!-- 商品名称 -->
				<view class="form-gorup">
					<view class="br-t padding-top-pd margin-top-xs pr">
						<view class="form-gorup-title">商品名称<text class="form-group-tips-must">*</text></view>
						<input type="text" name="tradeName" v-model="product_data.tradeName" maxlength="100"
							placeholder-class="cr-grey" class="cr-base" placeholder="商品名称">
					</view>
				</view>
				<!-- 款号 排序 -->
				<view class="form-gorup-tj oh br-t">
					<view class="form-gorup-item-left-gg-kh">
						<view class="form-gorup-title-gg">款号<text class="form-group-tips-must">*</text></view>
						<input type="text" name="barCode" v-model="product_data.barCode" maxlength="15"
							placeholder-class="cr-grey" class="cr-base" placeholder="款号">
					</view>
					<view class="form-gorup-item-left-gg-kh">
						<view class="form-gorup-title-gg">排序</view>
						<input type="number" name="sort" v-model="product_data.sort" placeholder-class="cr-grey"
							class="cr-base" placeholder="排序">
					</view>
				</view>
				<!-- 关键字 -->
				<view class="form-gorup">
					<view class="br-t padding-top-pd margin-top-xs pr">
						<view class="form-gorup-title">关键字</view>
						<input type="text" name="storeInfo" v-model="product_data.storeInfo" maxlength="200"
							placeholder-class="cr-grey" class="cr-base" placeholder="关键字最多200个字符">
					</view>
				</view>
				<!-- 品类，款式，品牌 -->
				<view class="form-gorup-tj oh br-t">
					<view class="form-gorup-item-left">
						<view class="form-gorup-title">品类</view>
						<picker name="categoryId" @change="select_category_event" :value="category_value"
							:range="category_list" range-key="cname">
							<view :class="'name ' + ((category_value == null) ? 'cr-grey' : 'cr-base' )">
								{{((category_list[category_value] || null) == null) ? '请选择品类' : category_list[category_value]['cname']}}
							</view>
						</picker>
					</view>
					<view class="form-gorup-item-left">
						<view class="form-gorup-title">款式<text class="form-group-tips-must">*</text></view>
						<picker name="cateId" @change="select_store_category_event" :value="store_category_value"
							:range="store_category_list" range-key="cateName">
							<view :class="'name ' + ((store_category_value == null) ? 'cr-grey' : 'cr-base' )">
								{{((store_category_list[store_category_value] || null) == null) ? '请选择款式' : store_category_list[store_category_value]['cateName']}}
							</view>
						</picker>
					</view>
					<view class="form-gorup-item-right">
						<view class="form-gorup-title">品牌系列</view>
						<picker name="brandSeriesId" @change="select_brand_series_event" :value="brand_series_value"
							:range="brand_series_list" range-key="name">
							<view :class="'name ' + ((brand_series_value == null) ? 'cr-grey' : 'cr-base' )">
								{{((brand_series_list[brand_series_value] || null) == null) ? '请选择品牌系列' : brand_series_list[brand_series_value]['name']}}
							</view>
						</picker>
					</view>
				</view>
				<view class="idcard-container padding-horizontal-main padding-top-main border-radius-main oh br-t">
					<view class="form-gorup bg-white form-container-upload oh">
						<view class="form-gorup-title">产品图<text class="form-group-tips-must">必传</text> <text class="form-size">(图片要求1：1尺寸，产品居中)</text> </view>
						<view class="form-upload-data">
							<view class="item fl">
								<uni-file-picker v-model="imageValue" :source-type="['album']" file-mediatype="image"
									mode="grid" file-extname="png,jpg" :limit="5" @select="select"
									title="最多上传5张图片,主图使用第一张" />
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="form-gorup">
					<view class="br-t padding-top-pd margin-top-xs pr">
						<view class="form-gorup-title">品牌系列推荐</view>
						<evan-switch v-model="product_data.isGood" :size="20" inactive-color="#B8DBF4" active-value="1"
							inactive-value="0"></evan-switch>
					</view>
				</view>
				<!-- 产品上下架 -->
				<!-- <view class="product_off_shelf">
					<view class="">状态</view>
					<view class="form-gorup default-checkbox margin-top-xl">
						<image class="va-m"
							:src="(product_data.status || 0) == 1 ? common_static_url_ative : common_static_url"
							mode="widthFix"></image>
						<text class="va-m margin-left-sm">上架</text>
					</view>
					<view class="form-gorup default-checkbox margin-top-xl" @tap="default_ads_change_event">
						<image class="va-m"
							:src="(product_data.status || 0) == 1 ? common_static_url : common_static_url_ative"
							mode="widthFix"></image>
						<text class="va-m margin-left-sm">下架</text>
					</view>
				</view> -->
				<!-- 规格增减 -->
				<view class="form-gorup oh">
					<view class="form-gorup-title oh">
						<!-- <text>规格</text> -->
						<view class="padding-right-s va-m fr oh">
							<button type="default" size="mini"
								class="bg-main-pair br-main-pair cr-white text-size-xs pa" @tap="addItem">添加</button>
						</view>
					</view>
				</view>
				<block v-for="(item, index) in dtableData" :key="index">
					<view class="form-gorup oh">
						<view class="form-gorup-title oh">
							<!-- <text>操作</text> -->
							<view class="padding-right-s va-m fr oh">
								<button type="default" size="mini"
									class="bg-main-pair br-main-pair cr-white text-size-xs pa"
									@tap="delItem(index)">删除</button>
							</view>
						</view>
						<view class="form-gorup-tj br-t">
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">金重<text class="form-group-tips-must">*</text></view>
								<input type="text" name="goldWeight" v-model="item.goldWeight" maxlength="100"
									placeholder-class="cr-grey" class="cr-base" placeholder="金重(g)">
							</view>
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">尺寸</view>
								<input type="text" v-model="item.measure" maxlength="30" placeholder-class="cr-grey"
									class="cr-base" placeholder="尺寸">
							</view>
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">库存<text class="form-group-tips-must">*</text></view>
								<input type="text" v-model="item.inventory" maxlength="30" placeholder-class="cr-grey"
									class="cr-base" placeholder="库存">
							</view>
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">销售价<text class="form-group-tips-must">*</text></view>
								<input type="text" name="salesPrice" v-model="item.salesPrice" maxlength="30"
									placeholder-class="cr-grey" class="cr-base" placeholder="销售价">
							</view>
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">批发价<text class="form-group-tips-must">*</text></view>
								<input type="text" name="tradePrice" v-model="item.tradePrice" maxlength="30"
									placeholder-class="cr-grey" class="cr-base" placeholder="批发价">
							</view>
							<view class="form-gorup-item-left-gg-kh">
								<view class="form-gorup-title-gg">条码号</view>
								<input type="text" v-model="item.barCode" maxlength="30" placeholder-class="cr-grey"
									class="cr-base" placeholder="条码号">
							</view>
						</view>
						<!-- <view class="form-gorup-item-left">
							<view class="form-gorup-title">市场价</view>
							<input type="text" name="marketPrice"  v-model="item.marketPrice" maxlength="30" placeholder-class="cr-grey" class="cr-base" placeholder="市场价">
						</view>
						<view class="form-gorup-item-right">
							<view class="form-gorup-title">成本价</view>
							<input type="text" name="costPrice" v-model="item.costPrice" maxlength="30" placeholder-class="cr-grey" class="cr-base" placeholder="批发价">
						</view> -->
					</view>
				</block>
				<!-- 配送方式  -->
				<!-- <view class="form-gorup-tj br-t">
					<checkbox-group @change="handleCheckafhalenAllChange">
						<label>
							<checkbox value="1" checked="true" />到店自提
						</label>
					</checkbox-group>
				</view>
				<view class="form-gorup oh" v-if="show_Postage">
					<view class="form-gorup-item-left" v-if="show_Postage">
						<view class="form-gorup-title">是否包邮<text class="form-group-tips-must">*</text></view>
						<evan-switch v-model="product_data.isPostage" :size="20" @change="changPostage"
							inactive-color="#B8DBF4" active-value="1" inactive-value="0"></evan-switch>
					</view>
					<view class="form-gorup-item-right" v-if="show_is_postage">
						<view class="form-gorup-title">邮费</view>
						<input type="number" name="postage" v-model="product_data.postage" placeholder-class="cr-grey"
							class="cr-base" placeholder="排序">
					</view>
				</view> -->
				<!-- 精品推荐  优惠推荐  品牌系列推荐-->
				<view class="form-gorup-tj oh br-t">
					<view class="form-gorup-item-left">
						<view class="form-gorup-title">精品推荐</view>
						<evan-switch v-model="product_data.isBest" :size="20" inactive-color="#B8DBF4" active-value="1"
							inactive-value="0"></evan-switch>
					</view>
					<view class="form-gorup-item-right">
						<view class="form-gorup-title">优惠推荐</view>
						<evan-switch v-model="product_data.isBenefit" :size="20" inactive-color="#B8DBF4"
							active-value="1" inactive-value="0"></evan-switch>
					</view>
					<view class="form-gorup-item-right">
						<view class="form-gorup-title">品牌系列推荐</view>
						<evan-switch v-model="product_data.isGood" :size="20" inactive-color="#B8DBF4" active-value="1"
							inactive-value="0"></evan-switch>
					</view>
					<view class="form-gorup-item-right">
						<text class="va-m margin-left-sm">{{ product_data.status == 1 ? '上架' : '下架' }}</text>
						<evan-switch v-model="product_data.status" :size="20" inactive-color="#B8DBF4"
						   active-value="1" inactive-value="0"></evan-switch>
					</view>
				</view>
				<!-- 上传视频 -->
				<view class="idcard-container padding-horizontal-main padding-top-main border-radius-main oh br-t">
					<view class="form-gorup bg-white form-container-upload oh">
						<view class="form-gorup-title">视频</view>
						<view class="form-upload-data">
							<view class="item fl">
								<uni-file-picker v-model="videoValue" :source-type="['album']" file-mediatype="video"
									mode="list"  file-extname="mp4" :limit="1" @select="videoselect" title="请上传MP4文件" />
							</view>
						</view>
					</view>
				</view>
				<view class="idcard-container padding-horizontal-main padding-top-main border-radius-main oh">
					<view class="form-gorup bg-white form-container-upload oh">
						<view class="form-gorup-title">图片详情 <text class="cr-red">可以不传,默认主图</text> </view>
						<view class="form-upload-data">
							<view class="item fl">
								<uni-file-picker v-model="descriptionValue" :source-type="['album']"
									file-mediatype="image" mode="grid" file-extname="png,jpg" :limit="10"
									@select="descriptionSelect" title="最多上传10张图片,按顺序排列,如不上传则以产品图为详情内容" />
							</view>
						</view>
					</view>
				</view>
				<view class="bottom-fixed">
					<view class="bottom-line-exclude oh">
						<button class="bg-main br-main bg-base round text-size cr-base" type="default" form-type="submit"
							hover-class="none"
							:disabled="form_submit_disabled_status">提交</button>
					</view>
				</view>
			</view>
		</form>
	</view>
</template>

<script>
	const app = getApp();
	import evanSwitch from "../../../components/evan-switch/evan-switch";

	export default {
		data() {
			return {
				//显示包邮情况
				show_Postage: false,
				//不包邮则显示邮费
				show_is_postage: true,
				common_static_url: "https://t1.chowtaiking.com.cn/img/ruoyi/2025/03/10/af1873cb84b34f21a16bfc0e4cb20522.png",
				common_static_url_ative: "https://t1.chowtaiking.com.cn/img/ruoyi/2025/03/10/6e13315dca0b4ca5aa9d9c26caa25531.png",
				dtableData: null,
				imageValue: [],
				videoValue: [],
				descriptionValue: [],
				product_data: {
					isBest: 0,
					isBenefit: 0,
					isGood: 0,
					status: 1,
					distribution: 0,
					afhalen: 1,
					isPostage: 0,
					postage: 0,
				},
				category_list: [],
				token: '',
				category_id: '',
				category_value: '',
				store_category_list: [],
				store_category_id: '',
				store_category_value: '',
				brand_series_list: [],
				brand_series_id: '',
				brand_series_value: '',
				ditems: [],
				admin_token: "",
				entryTime: 0,
				productId:''
			};
		},

		components: {
			evanSwitch
		},
		props: {},
		onLoad(params) {
			this.initItem();
		},
		
		onShow() {
			// 记录用户进来时间
			this.entryTime = Date.now();
		},
		onUnload() {
			this.OnEntryTime();
		},
		methods: {
			OnEntryTime() {
				var radarlog_data = {
					pageUrl: "pages/manage/product/pricing_gold",
					name: "黄金定价商品上新页",
					remark: "黄金定价商品上新页停留时间",
					entryTime: this.entryTime,
				}
				uni.request({
					url: app.globalData.get_request_url("radarlog/add"),
					data: radarlog_data,
					method: "POST",
					success: (res) => {
						console.log(res, "黄金定价商品上新页停留时间");
					}
				})
			},
			// 根据款号查询产品
			demand_envent(e) {
				var barcode = e.detail.value || '';
				if(barcode=='' || barcode.length == 0){
					return;
				}
				var url = app.globalData.data.request_admin_url + 'gold/storeProduct/queryBarcode/' + app
					.globalData.data.tenantId + '/' + barcode;
				uni.request({
					url: url,
					method: 'GET',
					dataType: 'json',
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: res => {
						if (res.data.code == 200) {
							var data = res.data.data;
							this.product_data = data;
							// 品类
							this.category_list.forEach((item, index) => {
								if (this.product_data.categoryId == item.categoryId) {
									this.category_value = index;
									this.category_id = item.categoryId;
								}
							});
							// 款式
							this.store_category_list.forEach((item, index) => {
								if (this.product_data.cateId == item.categoryId) {
									this.store_category_value = index;
									this.store_category_id = item.categoryId;
								}
							});
							// 品牌数据
							this.brand_series_list.forEach((item, index) => {
								if (this.product_data.brandSeriesId == item.brandSeriesId) {
									this.brand_series_value = index;
									this.brand_series_id = item.brandSeriesId;
								}
							})
							// 图片
							this.imageValue = data.fileList;
							this.ditems = data.attrList.attr;
							this.dtableData = data.attrList.value;
							this.productId = data.productId;
							uni.showToast({
								title: "查询成功"
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: "获取失败"
						})
					}
				});
			},
			// 获取品类
			get_category_list() {
				uni.request({
					url: app.globalData.data.request_admin_url + 'gold/storeProduct/queryCategoryList/' + app
						.globalData.data.tenantId,
					method: 'GET',
					dataType: 'json',
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: res => {
						if (res.data.code == 200) {
							var data = res.data.data;
							this.category_list = data

						} else {
							uni.showToast({
								title: res.data.msg
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: "获取失败"
						})
					}
				});
			},
			get_store_category_list() {
				uni.request({
					url: app.globalData.data.request_admin_url + "gold/storeProduct/quseryCateoryList/" + app
						.globalData.data.tenantId,
					method: 'GET',
					dataType: 'json',
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: res => {
						if (res.data.code == 200) {
							var data = res.data.data;
							this.store_category_list = data

						} else {
							uni.showToast({
								title: res.data.msg
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: "获取失败"
						})
					}
				});
			},
			get_brand_series_list() {
				uni.request({
					url: app.globalData.data.request_admin_url + "gold/storeProduct/queryBrandSeriesList/" + app
						.globalData.data.tenantId,
					method: 'GET',
					dataType: 'json',
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: res => {
						if (res.data.code == 200) {
							var data = res.data.data;
							this.brand_series_list = data

						} else {
							uni.showToast({
								title: res.data.msg
							})
						}
					},
					fail: () => {
						uni.showToast({
							title: "获取失败"
						})

					}
				});
			},
			// 省份事件
			select_category_event(e) {
				var index = e.detail.value || 0;
				if (index >= 0) {
					var data = this.category_list[index];

					this.category_value = index
					this.category_id = data.categoryId
				}
			},
			// 商品分类事件
			select_store_category_event(e) {
				var index = e.detail.value || 0;
				if (index >= 0) {
					var data = this.store_category_list[index];

					this.store_category_value = index
					this.store_category_id = data.categoryId
				}
			},
			// 商品分类事件
			select_brand_series_event(e) {
				var index = e.detail.value || 0;
				if (index >= 0) {
					var data = this.brand_series_list[index];

					this.brand_series_value = index
					this.brand_series_id = data.brandSeriesId
				}
			},
			handleCheckAllChange(e) {
				var temp_ads = this.product_data;
				let values = e.detail.value;
				if (values.includes("0")) {
					this.show_Postage = true;
					temp_ads['distribution'] = 1;
				} else {
					this.show_Postage = false;
					temp_ads['isPostage'] = 0;
					temp_ads['distribution'] = 0;
				}
				this.product_data = temp_ads
			},
			handleCheckafhalenAllChange(e) {
				var temp_ads = this.product_data;
				let values = e.detail.value;
				if (values.includes("1")) {
					temp_ads['afhalen'] = 1;
				} else {
					temp_ads['afhalen'] = 0;
				}
				this.product_data = temp_ads;
			},
			// handleSwitchChange(value) {
			// 	this.product_data.distribution = value ? 1 : 0;
			// 	this.show_Postage = value;
			// },
			changPostage(val) {
				if (val == 1) {
					this.show_is_postage = false;
					this.product_data['postage'] = 0;
				} else {
					this.show_is_postage = true;
				}
			},
			changisBest(e) {
				var temp_ads = this.product_data;
				let values = e.detail.value;
				if (values.includes("0")) {
					temp_ads['isBest'] = 1;
				} else {
					this.show_is_postage = false;
					temp_ads['isBest'] = 0;
				}


				this.product_data = temp_ads
			},
			changisBenefit(e) {
				var temp_ads = this.product_data;
				let values = e.detail.value;
				if (values.includes("0")) {
					temp_ads['isBenefit'] = 1;
				} else {
					this.show_is_postage = false;
					temp_ads['isBenefit'] = 0;
				}

				this.product_data = temp_ads
			},
			// 是否上架设置改变
			default_ads_change_event(e) {
				var temp_ads = this.product_data;
				temp_ads['status'] = (temp_ads.status || 0) == 1 ? 0 : 1;

				this.product_data = temp_ads
			},
			select(e) {
				uni.showLoading({
					title: '正在上传图片，请稍候...'
				});
				const tempFilePaths = e.tempFilePaths;
				for (var i = 0; i < tempFilePaths.length; i++) {
					this.uploadFile(tempFilePaths[i], '0')
				}
				//隐藏加载框
				uni.hideLoading();
			},
			descriptionSelect(e) {
				uni.showLoading({
					title: '正在上传图片，请稍候...'
				});
				const tempFilePaths = e.tempFilePaths;
				for (var i = 0; i < tempFilePaths.length; i++) {
					this.uploadFile(tempFilePaths[i], '1')
				}
				//隐藏加载框
				uni.hideLoading();
			},
			videoselect(e) {
				uni.showLoading({
					title: '正在上传视频，请稍候...'
				});
				const tempFilePaths = e.tempFilePaths;
				for (var i = 0; i < tempFilePaths.length; i++) {
					this.uploadFile(tempFilePaths[i], '2')
				}
				//隐藏加载框
				uni.hideLoading();
			},
			uploadFile(tempFilePaths, type) {
				// 图片上传
				uni.uploadFile({
					url: app.globalData.data.request_admin_url + "system/oss/upload",
					filePath: tempFilePaths,
					name: 'file',
					header: {
						'Authorization': 'Bearer ' + app.globalData.data.admin_token
					},
					success: (uploadFileRes) => {
						// 提取图片url
						const res = JSON.parse(uploadFileRes.data);

						if (res.code == 200) {

							if (type == 0) {

								this.imageValue.push({
									name: res.data.fileName,
									url: res.data.url,
									ossId: res.data.ossId
								});
							} else if (type == '1') {
								this.descriptionValue.push({
									name: res.data.fileName,
									url: res.data.url,
									ossId: res.data.ossId
								});
							} else if (type == '2') {
								this.videoValue.push({
									name: res.data.fileName,
									url: res.data.url,
									ossId: res.data.ossId
								});
							}
						}
					}
				});
			},
			// 对象转成指定字符串分隔
			listToString(list, separator) {
				let strs = "";
				separator = separator || ",";
				for (let i in list) {
					if (list[i].ossId) {
						strs += list[i].ossId + separator;
					}
				}
				return strs != "" ? strs.substr(0, strs.length - 1) : "";
			},
			// 对象转成详情内容
			generatedContent(list) {
				let strs = "";
				for (let i in list) {
					if (list[i].url) {
						strs += '<img src="' + list[i].url + '">';
					}
				}
				return strs != "" ? strs : "";
			},
			// 数据提交
			form_submit(e) {
				var form_data = e.detail.value;
				this.save_envent(form_data);
			},
			// 新增提交
			save_envent(form_data){
				form_data['type'] = '0'; //类型（0黄金商城1钻石商城)
				form_data['specType'] = '1'; //规格 0单 1多
				form_data['pricingModel'] = '0'; //计价方式
				// 数据校验
				var validation = [{
						fields: "tradeName",
						msg: "请填写商品名称"
					},
					{
						fields: "barCode",
						msg: "请填写款号"
					},
				];
				
				if (app.globalData.fields_check(form_data, validation)) {
					let list = this.dtableData;
					if (this.imageValue.length == 0) {
						uni.showToast({
							title: "请上传产品图"
						})
						return false;
					}
					form_data['sliderImage'] = this.listToString(this.imageValue, ',');
					if (this.videoValue.length > 0) {
						form_data['video'] = this.listToString(this.videoValue, ',');
					}
					if (this.category_id != '') {
						form_data['categoryId'] = this.category_id;
					}
					if (this.store_category_id != '') {
						form_data['cateId'] = this.store_category_id;
					} else {
						uni.showToast({
							title: "请选择款式"
						})
				
						return false;
					}
					if (this.brand_series_id != '') {
						form_data['brandSeriesId'] = this.brand_series_id;
					}
					var detail = [];
					var gwdetail = [];
					let index = 0;
					for (let i in list) {
						this.$set(list[i], 'attrName' + index, '默认');
						var measure = list[i].measure;
						if (measure == undefined || measure.length == 0 || measure == -1 || measure == 0) {
				
						} else {
							this.$set(list[i], 'attrName' + index, measure);
							this.$set(list[i].detail, list[i].detail.length, {
								'规格': measure
							});
							if (detail.length == 0) {
								detail.push(measure);
							} else {
								if (!detail.includes(measure)) {
									detail.push(measure);
								}
							}
						}
						var temp_value = list[i].goldWeight;
						if (temp_value == undefined || temp_value.length == 0 || temp_value == -1 || temp_value == 0) {
				
							uni.showToast({
								title: "请填写金重"
							})
							return false;
						} else {
							index++;
							this.$set(list[i], 'attrName' + index, temp_value);
							this.$set(list[i].detail, list[i].detail.length, {
								'金重': temp_value
							});
							if (gwdetail.length == 0) {
								gwdetail.push(temp_value);
							} else {
								if (!gwdetail.includes(temp_value)) {
									gwdetail.push(temp_value);
								}
				
							}
				
						}
						temp_value = list[i].salesPrice;
						if (temp_value == undefined || temp_value.length == 0 || temp_value == -1 || temp_value == 0) {
							uni.showToast({
								title: "请填写销售价"
							})
							return false;
						}
						temp_value = list[i].tradePrice;
						if (temp_value == undefined || temp_value.length == 0 || temp_value == -1 || temp_value == 0) {
				
							uni.showToast({
								title: "请填写批发价"
							})
							return false;
						}
						temp_value = list[i].inventory;
						if (temp_value == undefined || temp_value.length == 0 || temp_value == -1 || temp_value == 0) {
							uni.showToast({
								title: "请填写库存"
							})
							return false;
						}
				
						temp_value = list[i].marketPrice;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].marketPrice = '0.00';
						}
						temp_value = list[i].costPrice;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].costPrice = '0.00';
						}
						temp_value = list[i].stoneCount;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].stoneCount = '0';
						}
						temp_value = list[i].stoneWeight;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].stoneWeight = '0.00';
						}
						temp_value = list[i].assistantStoneCount;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].assistantStoneCount = '0';
						}
						temp_value = list[i].assistantStoneWeight;
						if (temp_value == undefined || temp_value.length == 0) {
							list[i].assistantStoneWeight = '0.00';
						}
						index = 0;
					}
					this.dtableData = list;
					if (detail.length > 0) {
						this.$set(this.ditems, this.ditems.length, {
							attrName: '尺寸',
							detailValue: '',
							detail: detail
						});
					}
					if (gwdetail.length > 0) {
						this.$set(this.ditems, this.ditems.length, {
							attrName: '金重',
							detailValue: '',
							detail: gwdetail
						});
					}
					const jsonString = JSON.stringify({
						items: this.ditems,
						attrs: this.dtableData
					});
					form_data['jsonStr'] = jsonString;
					form_data['isBest'] = this.product_data['isBest'];
					form_data['isGood'] = this.product_data['isGood'];
					form_data['isBenefit'] = this.product_data['isBenefit'];
					form_data['status'] = this.product_data['status'];
					form_data['distribution'] = this.product_data['distribution'];
					form_data['afhalen'] = this.product_data['afhalen'];
					form_data['isPostage'] = this.product_data['isPostage'];
					form_data['postage'] = this.product_data['postage'];
					form_data['isGood'] = this.product_data['isGood'];
					form_data['tenantId'] = app.globalData.data.tenantId;
					form_data['productId'] = this.productId;  //产品id
					
					let content = '';
					if (!typeof this.descriptionValue == '[]') {
						content = this.generatedContent(this.descriptionValue);
					} else {
						content = this.generatedContent(this.imageValue);
					}
					if (content != '') {
						content = '<p>' + content + "</p>";
					}
					form_data['description'] = content;
					this.form_submit_disabled_status = true;
					uni.showLoading({
						title: '处理中...'
					});
					let mothod = 'POST';
					if(this.productId != ''){
						mothod = 'PUT';
					}
					uni.request({
						url: app.globalData.data.request_admin_url + "gold/storeProduct",
						method: mothod,
						data: form_data,
						dataType: 'json',
						header: {
							'Authorization': 'Bearer ' + app.globalData.data.admin_token
						},
						success: res => {
							uni.hideLoading();
							if (res.data.code == 200) {
								uni.showToast({
									title: res.data.msg
								})
								setTimeout(function() {
									uni.navigateBack();
								}, 1000);
							} else {
								this.form_submit_disabled_status = false
				
								if (app.globalData.is_login_check(res.data)) {
									uni.showToast({
										title: res.data.msg
									})
				
								} else {
									uni.showToast({
										title: '提交失败，请重试！'
									})
								}
							}
						},
						fail: () => {
							this.form_submit_disabled_status = false
							uni.hideLoading();
							uni.showToast({
								title: '服务器请求出错'
							})
				
						}
					});
				}
			},
			initItem() {
				var detai = [];
				detai.push({
					'规格': '默认'
				});
				this.ditems.push({
					attrName: '规格',
					detailValue: '',
					detail: ['默认']
				})
				this.dtableData = []
				this.dtableData.push({
					picture: '',
					stoneCount: '',
					stoneWeight: '',
					stoneType: '',
					assistantStoneCount: '',
					assistantStoneWeight: '',
					assistantStoneType: '',
					certificateCode: '',
					salesPrice: '',
					marketPrice: '',
					costPrice: '',
					tradePrice: '',
					inventory: '',
					barCode: '',
					goldWeight: '',
					measure: '',
					brokerage: '',
					brokerageTwo: '',
					detail: detai,
				});
				this.get_category_list();
				this.get_store_category_list();
				this.get_brand_series_list();
			},
			addItem() {
				var detai = [];
				detai.push({
					'规格': '默认'
				});
				this.dtableData.push({
					picture: '',
					stoneCount: '',
					stoneWeight: 0.00,
					stoneType: '',
					assistantStoneCount: '',
					assistantStoneWeight: 0.00,
					assistantStoneType: '',
					salesPrice: 0.00,
					marketPrice: 0.00,
					costPrice: 0.00,
					tradePrice: 0.00,
					inventory: '',
					barCode: '',
					goldWeight: '',
					measure: '',
					brokerage: '',
					brokerageTwo: '',
					detail: detai,
				})
			},
			delItem(k) {
				this.dtableData.splice(k, 1);
			}
		}
	};
</script>

<style>
	/**
	 * 页面底部浮动、增加底部边距
	 */
	/**
	 * 底部浮动
	 */
	.bottom-fixed {
	    position: fixed;
	    left: 0;
	    bottom: 0;
	    width: 100%;
	    box-sizing: border-box;
	    z-index: 2;
	}
	
	.bg-base {
	    background-color: #f5f5f5 !important;
	}
	.page-bottom-fixed {
		padding-bottom: 120rpx !important;
	}
	/* 根据款号查询 */
	.demand{
		border: red 1px solid;
		padding: 10rpx;
		border-radius: 20rpx;
	}

	/* 产品上下架 */
	.product_off_shelf {
		display: flex;
		align-items: center;
		/* justify-content: space-between; */
		padding-left: 20rpx;
	}

	.padding-top-pd {
		display: flex;
		align-items: center;
	}

	/**
	 * 表单
	 */
	.form-container .form-gorup {
		padding: 10rpx;
		border-radius: 20rpx;
	}

	.form-gorup-tj {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 10rpx;
		font-size: 13px;
	}

	.form-container .form-gorup .form-gorup-item-left {
		float: left;
		padding-right: 20rpx;
	}
	.form-gorup-item-left-gg{
		width: 33.33%;
		display: flex;
		align-items: center;
		font-size: 13px;
	}
	.form-gorup-item-left-gg input{
		font-size: 12px;
	}
	.form-gorup-item-left-gg-kh{
		width: 50%;
		display: flex;
		align-items: center;
	}
	.form-gorup-item-left-gg-kh input{
		padding-left: 10rpx;
	}
	.form-gorup-title-gg{
		display: flex;
		align-items: center;
		width: 45%;
		font-size: 13px;
	}

	.form-container .form-gorup .form-gorup-item-right {
		float: right;
		padding-left: 20rpx;
		border-left: 1px solid #f7f7f7;
	}

	/* .form-container .form-gorup .form-gorup-item-left,
	.form-container .form-gorup .form-gorup-item-right {
		width: calc(33.33% - 20rpx - 1px);
	} */

	.form-container .form-gorup-submit {
		padding: 20rpx 0;
	}

	.form-container .form-gorup:not(.form-gorup-submit) {
		background: #fff;
	}

	.form-container .form-gorup-title {
		margin-bottom: 5rpx;
		font-weight: 500;
		padding-right: 10rpx;
		font-size: 13px;
	}

	.form-container .form-group-tips,
	.form-container .form-group-tips-must {
		/* margin-left: 20rpx; */
		font-size: 24rpx;
		color: #ccc;
	}

	.form-container .form-group-tips-must {
		color: #f00;
	}
	
	.form-size{
		font-size: 10px;
		color: red;
	}

	.form-container .form-gorup input,
	.form-container .form-gorup textarea,
	.form-container .form-gorup .picker {
		border-radius: 0;
		/* width: 100%; */
		box-sizing: border-box;
		font-size: 20rpx;
	}

	.form-container .form-gorup input,
	.form-container .form-gorup .picker,
	.form-container .form-gorup .radio-gorup {
		height: 70rpx;
		line-height: 70rpx;
		padding-left: 10rpx;
	}

	.form-container .form-gorup textarea {
		padding: 0;
		height: 150rpx !important;
		margin-top: 20rpx;
	}

	.form-container .form-gorup-text {
		padding: 20rpx 10rpx;
	}

	.form-container .form-gorup .switch {
		margin: 30rpx 0 20rpx 0;
	}

	.form-container .form-gorup .radio-gorup .radio radio {
		transform: scale(0.7);
	}

	.form-container .form-gorup .radio-gorup .radio:not(:last-child) {
		margin-right: 50rpx;
	}

	/**
	 * 表单图片上传
	 */
/* 	.form-container-upload .form-gorup-title {
		margin-bottom: 20rpx;
	} */

	.form-container-upload .form-upload-data .item {
		margin: 10rpx 10rpx 0 0;
		position: relative;
		font-size: 13px;
	}

	.form-container-upload .form-upload-data .delete-icon {
		position: absolute;
		top: 0;
		right: 0;
		color: #e5e5e5;
		background-color: #d9534f;
		padding: 5rpx 18rpx;
		font-size: 36rpx;
		border: 1px solid #eee;
		border-radius: 50rpx;
		line-height: 44rpx;
		z-index: 1;
	}

	.form-container-upload .form-upload-data image {
		width: 100%;
		height: 100%;
		padding: 5rpx;
		border: 1px solid #eee;
		display: block;
		border-radius: 10rpx;
	}

	.form-container-upload .upload-icon {
		margin-top: 10rpx;
		width: 160rpx;
		height: 160rpx;
		border: 1px dashed #e9e9e9;
		display: block;
		border-radius: 10rpx;
	}
	.uni-file-picker button{
		width: 180rpx !important;
		height: 70rpx;
		font-size: 11px;
		text-align: center;
		line-height: 70rpx;
	}
	.uni-file-picker .uni-file-picker__header .file-title{
		font-size: 20rpx;
		color: #666;
	}

	/* .padding-main {
	    padding: 20rpx;
	} */

	.br-t {
		border-top: 1px solid #f7f7f7 !important;
	}

	.pr {
		position: relative;
	}

	/**
 * 统一颜色
 * 文本基础色、白色、黑色、灰色、浅灰色、红色、黄色、绿色、蓝色
 */
	.cr-base {
		color: #666 !important;
	}

	.cr-white {
		color: #000 !important;
	}

	.cr-black {
		color: #000 !important;
	}

	.cr-gray {
		color: #888 !important;
	}

	.cr-grey {
		color: #9A9A9A !important;
	}

	.cr-grey-white {
		color: #e7e7e7 !important;
	}

	.cr-red {
		color: #f00 !important;
		font-size: 12px;
		padding-left: 5rpx;
	}

	.cr-yellow {
		color: #f6c133 !important;
	}

	.cr-green {
		color: #1AAD19 !important;
	}

	.cr-blue {
		color: #2196F3 !important;
	}

	.cr-b5 {
		color: #b59364 !important;
	}

	.bg-white {
		background-color: #fff !important;
	}

	.oh {
		overflow: hidden;
	}

	.va-m {
		vertical-align: middle;
	}

	.margin-top-xl {
		margin-top: 25rpx;
	}

	/* .margin-top-xs {
		margin-top: 5rpx;
	} */

	.margin-left-sm {
		margin-left: 10rpx;
	}

	.padding-right-s {
		width: 160rpx;
		height: 60rpx;
		padding-bottom: 10rpx;
		/* padding-right: 130rpx; */
	}
	.padding-right-s button{
		width: 160rpx;
		height: 60rpx;
	}

	.default-checkbox image {
		width: 35rpx;
		height: 35rpx !important;
	}
</style>